<?php
namespace app\html\controller;
use think\Controller;

class Detail extends Controller 
{
    public function index($id,$vehicle_plate_number,$tel,$photo,$companyTitle,$s_time,$e_time,$title,$id_card,$realname)
    {
        $detail = $this->_getDetail($id);

        $this->assign('photoList',$detail['photoList']);
        $this->assign('signList',$detail['signList']);
        $this->assign('videoList',$detail['videoList']);
        $this->assign('vehicle_plate_number',$vehicle_plate_number);
        $this->assign('tel',$tel);
        $this->assign('photo',$photo);
        $this->assign('realname',$realname);
        $this->assign('id_card',$id_card);
        $this->assign('title',$title);
        $this->assign('companyTitle',$companyTitle);
        $this->assign('s_time',$s_time);
        $this->assign('e_time',$e_time);

    	return $this->fetch();
    }

    private function _getDetail($id)
    {
        # 计划里面的视频
        $map = [
            'driver_train_id' => $id
        ];
        $videos = db('DriverTrainVideo')->alias('a')->join('video b','a.video_id = b.id','LEFT')->field('a.*,b.title')->order('id DESC')->where($map)->select();
        $videoList = [];

        foreach ($videos as $v) {
            $v['durationDone'] = secToTime($v['duration_done']);
            $v['Duration'] = secToTime($v['duration']);
            $v['Percent'] = formatMoneyShow($v['percent']);
            $v['isDone'] = $v['duration'] == $v['duration_done'] ? '完成' : '未完成';
            $videoList[] = $v;
        }

        $logs = db('DriverTrainLearningLog')->where($map)->select();
        $photoList = $signList = [];

        foreach ($logs as $v) {
            $v['createTime'] = date('Y-m-d H:i:s',$v['create_time']);
            if($v['type'] == '签名') $signList[] = $v;
            if($v['type'] == '拍照') $photoList[] = $v;
        }
        
        $data = [
            'videoList' => $videoList,
            'photoList' => $photoList,
            'signList' => $signList,
            'logs' => $logs
        ];

        return $data;
    }
}
